<?php
namespace app\admin\controller;


class Cate extends Base
{
    public function lists()
    {
        $this->assign("list", $upcatelist = model("cate")->where(['cms_id' => $this->cms['id']])->order("sort asc,id asc")->select());
        return view();
    }

    public function edit()
    {
        $upcatelist = model("cate")->where(['cms_id' => $this->cms['id'], "upid" => 0])->order("id asc")->select();
        if ($this->_edit("cate", ['cms_id' => $this->cms['id']])) {
            $this->redirect("cate/lists");
        };
        $this->assign("upcatelist", $upcatelist);
        return view();
    }

    public function delete()
    {
        $subcount = model("cate")->where("upid", input("get.id"))->count();
        $artcount = model("article")->where("cate_id", input("get.id"))->count();
        if ($subcount != 0) {
            $this->error('此分类下含有下级分类，不能删除');

        } elseif ($artcount != 0) {
            $this->error('此分类下含有文章，不能删除');
        } else {
            $this->_delete("cate", ['cms_id' => $this->cms['id'], "id" => input("get.id")], "cate/lists");
        }

    }


}
